
import 'dart:async';

import 'package:flutter/services.dart';

class FlutterTcos {
  static const MethodChannel _channel = MethodChannel('flutter_tcos');

  static Future<String?> get platformVersion async {
    final String? version = await _channel.invokeMethod('getPlatformVersion');
    return version;
  }

  static Future initCosServer(final String appID, final String bucket, 
  final String region, final String signUrl, final String cookie, final int systemId) async {
    final int ret = await _channel.invokeMethod("initCosServer", {
      "appID": appID,
      "bucket": bucket,
      "region": region,
      "signUrl": signUrl,
      "cookie": cookie,
      "systemId": systemId
    });
    return ret;
  }

  static Future<String?> upload(final String localPath, final String cosPath) async {
    final String? url = await _channel.invokeMethod("upload", {
      "originLocalPath": localPath,
      "targetPath": cosPath
    });
    print("cos:" + (url ?? "null"));
    return url;
  }

  static Future<String?> uploadWithName(final String localPath, final String cosPath) async {
    final String? url = await _channel.invokeMethod("uploadWithName", {
      "originLocalPath": localPath,
      "targetPath": cosPath
    });
    print("cos:" + (url ?? "null"));
    return url;
  }
}
